def prost(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return n > 1
n = int(input())
n = str(n)
s = [0]
for i in range(len(n)):
    for j in range(i+1, len(n) + 1):
        k = int(n[i:j])
        if prost(k):
            s.append(k)
print(max(s))